//app.js
App({
  onLaunch: function() {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        if (res.code) {
          // 发起网络请求
          var that = this
          wx.request({
            url: this.globalData.serverUrl + '/admin/user/wxlogin',
            method: 'POST',
            data: {
              code: res.code
            },
            success(res) {
              var token = res.data.info.token
              wx.setStorageSync('uid', ((/[1-9][0-9]*/i).exec(token))[0])
              wx.setStorageSync('token', token)
              wx.setStorageSync('phone', res.data.info.phone)
              wx.setStorageSync('wechat', res.data.info.wechat)
            }
          })
        }
      }
    })
    var sysInfo = wx.getSystemInfoSync()
    var titleBarHeight = 48
    if (sysInfo.system.indexOf('ios') != -1) {
      titleBarHeight = 44
    }
    this.globalData.height = sysInfo.screenHeight,
    this.globalData.width = sysInfo.screenWidth,
    this.globalData.barHeight = sysInfo.statusBarHeight + (titleBarHeight - 32) / 2 - 1
  },
  globalData: {
    token: '',
    height: 0,
    width: 0,
    barHeight: 0,
    userInfo: null,
    serverUrl: 'https://zouzou.work',
  }
})